/*
 * Project: BoboDesignPattern
 * 
 * File Created at 2019年3月26日
 * 
 * Copyright 2012 Greenline.com Corporation Limited.
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of
 * Greenline Company. ("Confidential Information").  You shall not
 * disclose such Confidential Information and shall use it only in
 * accordance with the terms of the license agreement you entered into
 * with Greenline.com.
 */
package test.lesson3.sort;

import java.util.Arrays;

/**
 * @Type RadixSort
 * @Desc
 * @author 52489
 * @date 2019年3月26日
 * @Version V1.0
 */
public class RadixSort {

    public static void sort(int nums[]) {
        int max = 0;
        for (int i = 0; i < nums.length; i++) {
            if (nums[i] > max) {
                max = nums[i];
            }
        }

        int weishu = (max + "").length();

        int tmp[] = new int[nums.length];

        for (int i = 1; i <= weishu; i++) {
            int tmp1[][] = new int[10][nums.length];
            for (int j = 0; j < nums.length; j++) {
                String numStr = nums[j] + "";
                if (numStr.length() < i) {
                    for (int k = 0; k < tmp1[0].length; k++) {
                        if (tmp1[0][k] == 0) {
                            tmp1[0][k] = nums[j];
                            break;
                        }
                    }
                } else {
                    char x = numStr.charAt(numStr.length() - i);
                    int weishuNum = Integer.parseInt(String.valueOf(x));
                    for (int k = 0; k < tmp1[weishuNum].length; k++) {
                        if (tmp1[weishuNum][k] == 0) {
                            tmp1[weishuNum][k] = nums[j];
                            break;
                        }
                    }
                }

            }
            System.out.println("第" + i + "位排序分布");
            int k = 0;
            for (int j = 0; j < tmp1.length; j++) {
                for (int j2 = 0; j2 < tmp1[j].length; j2++) {
                    int num = tmp1[j][j2];
                    if (num != 0) {
                        System.out.print(tmp1[j][j2] + "__" + k + "~");
                        tmp[k] = tmp1[j][j2];
                        k++;
                    } else {
                        continue;
                    }
                }
            }
            System.out.println("\n");
            nums = tmp.clone();
            tmp = new int[nums.length];
            System.out.println(Arrays.toString(nums));

        }

    }

    public static void main(String[] args) {
        int nums[] = { 12, 4, 531, 31, 66, 14, 125, 1, 43, 54 };
        System.out.println(Arrays.toString(nums));
        String numStr = "123";
        System.out.println(numStr.length());
        int weishuNum = Integer.valueOf(numStr.substring(numStr.length() - 1 - 0));
        // numStr.length()-1-0);
        System.out.println(weishuNum + "~~~~");
        String x = "123";

        System.out.println(x.charAt(2));
        int a[] = { 1, 2, 3, 5 };
        int b[] = a.clone();
        b = new int[a.length];
        // System.out.println(Arrays.toString(b));

        sort(nums);

    }

}
